<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<c-rt:set var="tp" value="${pu:pageableTag('tpp', 10, 10)}"/>
<c-rt:if test="${empty param.priority && empty param.status}">
${pu:reqSet('hql', 'from WorkOrder w where 
(
	createUser=? and status!=?
)

order by status asc, createDate desc, forwardFinishTime desc
') }
${pu:listAdd('params', pu:username()) }
${pu:listAdd('params', pu:toInteger(2)) }
<c-rt:set var="hqlR">
${hql }
</c-rt:set>
${pu:reqSet('results', pu:queryByHql(hqlR, pu:arrayGet('params'), tp)) }




</c-rt:if>
<c-rt:if test="${!empty param.priority || !empty param.status}">
${pu:reqSet('hql', 'from WorkOrder w where 
(
	createUser=?
)')}

${pu:reqSet('hqlOrder', '

order by status asc, createDate desc, forwardFinishTime desc
') }
${pu:listAdd('params', pu:username()) }
<c-rt:if test="${!empty param.priority}">
${pu:reqSet('hql1', ' and priority=? ') }
${pu:listAdd('params', pu:toInteger(param.priority)) }
</c-rt:if>
<c-rt:if test="${!empty param.status}">
${pu:reqSet('hql2', ' and status=? ') }
${pu:listAdd('params', pu:toInteger(param.status)) }
</c-rt:if>
<c-rt:set var="hqlR">
${hql }${hql1 }${hql2 }${hqlOrder }
</c-rt:set>
${pu:reqSet('results', pu:queryByHql(hqlR, pu:arrayGet('params'), tp)) }

${pu:criteriaForName('com.yaodian100.crm.workorder.entity.WorkOrder') }
${pu:criteriaAdd(
	pu:criteria('eq', 'createUser', pu:username())
) }

<c-rt:if test="${!empty param.priority}">
${pu:criteriaAdd(pu:criteria('eq', 'priority', pu:toInteger(param.priority))) }
</c-rt:if>
<c-rt:if test="${!empty param.status}">
${pu:criteriaAdd(pu:criteria('eq', 'status', pu:toInteger(param.status))) }
</c-rt:if>
${pu:criteriaAddOrder(pu:criteriaOrderDesc('createDate')) }
${pu:criteriaAddOrder(pu:criteriaOrderAsc('status')) }
${pu:reqSet('results', pu:criteriaResult(tp)) }
</c-rt:if>
<c-rt:set var="hqlUser" value="from User where group.code=?"/>
<c-rt:set var="paramsUser" value="${pu:addToList('parasUser', 'C.01')}"/>
<c-rt:set var="users" value="${pu:queryByHql(hqlUser, paramsUser, null)}"/>
${pu:reqSet('menu', pu:get('com.yaodian100.core.menu.entity.Menu', 'WorkOrder.status')) }
<br />
<h1>我建立的工单

</h1>
<form name="workOrderForm">
<table>
<tr>
<td>
处理等级:<select name="priority">
<option value="">请选择</option>
<option value="0" <c-rt:if test="${param.priority == '0'}">selected="selected"</c-rt:if>>函件</option>
<option value="1" <c-rt:if test="${param.priority == '1'}">selected="selected"</c-rt:if>>一般件</option>
<option value="2" <c-rt:if test="${param.priority == '2'}">selected="selected"</c-rt:if>>急件</option>
<option value="3" <c-rt:if test="${param.priority == '3'}">selected="selected"</c-rt:if>>特急件</option>
</select>
状态:
<select name="status">
<option value="">请选择</option>
<c-rt:forEach items="${menu.options}" var="option">
<option value="${option.value.code }" <c-rt:if test="${option.value.code==param.status }">selected="selected"</c-rt:if>>${option.value.name }</option>
</c-rt:forEach>
</select>
<input type="button" id="searchWorkOrder" value="search"/></td><td><input type="button" id="questionToAdd" value="建立工单"/>

	<input type="hidden" name="questionType" value="CommonQuestion"/>

<input type="button" value="批次成立工单" onClick="location.href='<c-rt:url value="/cs/page.do?questionType=CommonQuestion&iamlazy=questionBatch&formType=workOrder"/>'">
<input type="button" value="批次成立断／缺货工单" onclick="location.href='<c-rt:url value="/cs/page.do?iamlazy=toOutOfStockBatch"/>'"/>

</td>

</tr>
</table>
</form>

<table class="tb-1" width="100%">
		<thead>
			<tr>
				<th></th>
				<th>ID</th>
				<th>前单ID</th>
				<th>问题单编号</th>
				<th>订单编号</th>
				<th>处理等级</th>
				<th>状态</th>
				<th>类型</th>
				<th>短描述</th>
				
				<th>处理人</th>
				<th>处理群组</th>
				<th>审核群组</th>
				<th>审核状态</th>
				<th>建立日期</th>
				<th>转单回覆日期</th>
			</tr>
		</thead>
		<tbody>
			<c-rt:forEach items="${results}" var="result" varStatus="rows_index">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffff"
			</c-rt:set>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>24}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#aaffff"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>48}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffaa"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>72}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffaaff"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${result.status==2}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffff"
			</c-rt:set>
			</c-rt:if>
			<c-rt:set var="domain" value="${pu:get('com.yaodian100.crm.cs.entity.Question', result.domainId)}"/>
				<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}" ${theStyle }>
					<td>
					<input type="button" value="追踪" onclick="doAR('<%=application.getContextPath() %>/workOrder/page.do?iamlazy=trace&AJAX=true&refreshZone=main&id=${result.id}', 'dialog');openDialog('trace', '', 700,300)"/>
					<input type="button" value="明细" onclick="location.href='<%=application.getContextPath() %>/cs/page.do?iamlazy=viewQuestion&id=${result.id}'"/>
					<%--
					<c-rt:if test="${(pu:isCRMManager(pu:username()) &&result.owner.username!=pu:username() && result.status!='2') || (!pu:isCRMManager(pu:username()) && empty result.owner && result.status!='2')}">
					<input type="button" value="取得" onclick="location.href='<%=application.getContextPath() %>/workOrder/get.do?id=${result.id}'"/>
					</c-rt:if>
					--%>
					</td>
					<td>${result.id }</td>
					<td>${result.parent.id }</td>
					<td>${domain.id }</td>
					<td>${result.question.extraValue['orderId'].value }</td>
					<td>
					<c-rt:if test="${result.priority==0}">
					函件
					</c-rt:if>
					<c-rt:if test="${result.priority==1}">
					一般件
					</c-rt:if>
					<c-rt:if test="${result.priority==2}">
					急件
					</c-rt:if>
					<c-rt:if test="${result.priority==3}">
					特急件
					</c-rt:if>
					
					</td>
					<td>${pu:menuOption('WorkOrder.status', pu:toString(result.status)).name }</td>
					
					<td>
					<c-rt:if test="${domain.type.name=='CommonQuestion' }">
						<c-rt:if test="${domain.extraValue['isProductQAA'].value=='true' }">
							商品问答
						</c-rt:if>
						<c-rt:if test="${domain.extraValue['isProductQAA'].value!='true' }">
							客服问答
						</c-rt:if>
					</c-rt:if>
					<c-rt:if test="${domain.type.name!='CommonQuestion' }">
					${domain.type.description }
					</c-rt:if>
					
					</td>
					
					<td>${result.shortDesc }</td>
					
					<td>
					
					${result.owner.username }
					
					</td>
					<td>
					<c-rt:if test="${!empty result.responseGroup}">
					${pu:get('com.yaodian100.core.admin.entity.Group', result.responseGroup).description }(${result.responseGroup })
					</c-rt:if>
					</td>
					<td>
					<c-rt:if test="${!empty result.approveGroup}">
					${pu:get('com.yaodian100.core.admin.entity.Group', result.approveGroup).description }(${result.approveGroup })
					</c-rt:if>
					</td>
					<td>
					<c-rt:if test="${result.approveStatus==0 }">
					待审核
					</c-rt:if>
					<c-rt:if test="${result.approveStatus==1 }">
					已核可
					</c-rt:if>
					<c-rt:if test="${result.approveStatus==2 }">
					<span style="color:red">已注销</span>
					</c-rt:if>
					</td>
					<td>
					<fmt-rt:formatDate value="${result.createDate }" pattern="yyyy/MM/dd HH:mm"/>
					</td>
					<td>
					${pu:reqSet('replyHql', 'from WorkOrder where parent.id=?') }
					${pu:reqSet('replyList', null) }
					${pu:listAdd('replyList', result.id) }
					${pu:reqSet('replyWorkOrder', pu:queryByHql(replyHql, pu:arrayGet('replyList'), null)) }
					
					<c-rt:if test="${!empty replyWorkOrder}">
					<c-rt:if test="${!empty replyWorkOrder[0].finishTime}">
					<fmt-rt:formatDate value="${replyWorkOrder[0].finishTime}" pattern="yyyy-MM-dd HH:mm"/>
					</c-rt:if>
					<c-rt:if test="${empty replyWorkOrder[0].finishTime}">
					<b>尚未回覆</b>
					</c-rt:if>
					</c-rt:if>
					<c-rt:if test="${empty replyWorkOrder}">
					未转单
					</c-rt:if>
					</td>
				</tr>
			</c-rt:forEach>
		</tbody>
	</table>
<c-rt:set var="url">
<%=application.getContextPath() %>/workOrder/page.do
</c-rt:set>
<pageable:Pageable url="${url}" escapeparams="iamlazy,refreshZone,AJAX" parameter="iamlazy=myWorkOrder" formname="woForm" key="tpp"></pageable:Pageable>
<table width="100%">
<tr>
<td align="right">
${pu:reqSet('currentPage', param.tpp_pageable_currentPage) }
<c-rt:if test="${empty param.tpp_pageable_currentPage}">
${pu:reqSet('currentPage', 1) }
</c-rt:if>
目前在第${currentPage }页, 资料共${tp.totalRecords }笔</td>
</tr>
</table>
<script>
$(document).ready(function(){
	$('#searchWorkOrder').click(function(){
		doAR('<%=application.getContextPath() %>/workOrder/page.do?iamlazy=myWorkOrder&AJAX=true&refreshZone=main', 'main', 'workOrderForm');
	});
	$('#questionToAdd').click(function(){
		doAR('<%=application.getContextPath() %>/cs/page.do?iamlazy=selectType&AJAX=true&refreshZone=main&formType=workOrder', 'main');
	});
});
</script>